package com.ny.shiyan;

import java.util.Scanner;

public class shiyan1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String employeeId = "";
        String name = "";
        String department = "";

        double baseSalary = 0;
        double bonus = 0;
        double deduction = 0;

        boolean exit = false;

        while (!exit) {
            System.out.println("职工工资管理系统");
            System.out.println("1. 输入职工个人信息");
            System.out.println("2. 输入职工工资信息");
            System.out.println("3. 计算并显示工资");
            System.out.println("4. 退出系统");

            int choice = 0;
            System.out.print("请选择操作:");
            if (scanner.hasNextInt()) {
                choice = scanner.nextInt();
                scanner.nextLine();
            } else {
                System.out.println("错误：请输入数字选项！");
                scanner.nextLine();
                continue;
            }

            switch (choice) {
                case 1:
                    System.out.println("输入职工个人信息");
                    System.out.print("工号:");
                    employeeId = scanner.nextLine();

                    System.out.print("姓名:");
                    name = scanner.nextLine();

                    System.out.print("部门:");
                    department = scanner.nextLine();

                    System.out.println("信息已保存！");
                    break;

                case 2:
                    System.out.println("输入工资信息");
                    System.out.print("基本工资: ");
                    baseSalary = scanner.nextDouble();

                    System.out.print("奖金: ");
                    bonus = scanner.nextDouble();

                    System.out.print("扣款: ");
                    deduction = scanner.nextDouble();
                    scanner.nextLine();

                    System.out.println("工资信息已保存！");
                    break;

                case 3:
                    if (employeeId.isEmpty()) {
                        System.out.println("错误：请先输入职工个人信息！");
                    } else if (baseSalary == 0 && bonus == 0 && deduction == 0) {
                        System.out.println("错误：请先输入工资信息！");
                    } else {
                        double totalSalary = baseSalary + bonus - deduction;

                        System.out.println("工资结算单");
                        System.out.println("工号: " + employeeId);
                        System.out.println("姓名: " + name);
                        System.out.println("部门: " + department);
                        System.out.printf("基本工资: ¥%.2f\n", baseSalary);
                        System.out.printf("奖金: ¥%.2f\n", bonus);
                        System.out.printf("扣款: ¥%.2f\n", deduction);
                        System.out.printf("实发工资: ¥%.2f\n", totalSalary);
                    }
                    break;

                case 4:
                    exit = true;
                    System.out.println("感谢使用，再见！");
                    break;

                default:
                    System.out.println("无效选择，请重新输入!");
            }
        }
        scanner.close();
    }
}
